import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import axios from 'axios'
import * as echarts from 'echarts'

import VMdPreview from '@kangc/v-md-editor/lib/preview';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';

// import { GridLayout, GridItem } from 'vue-grid-layout'
//
// axios.defaults.baseURL = 'http://8.141.83.237:8088'
axios.defaults.baseURL = 'http://127.0.0.1:8088'
// axios.defaults.headers['Content-Type'] = 'application/json'

axios.interceptors.request.use(
  config => {
    const satoken = window.sessionStorage.getItem('satoken')
    console.log('satoken:', satoken); // 添加日志输出
    if (satoken !== null && satoken !== '') {
      config.headers.satoken = satoken
    } else {
      console.warn('satoken is empty or null'); // 添加日志输出
    }
    return config
  }
)

VMdPreview.use(vuepressTheme);

const app = createApp(App)
app.provide('$axios', axios)
app.config.globalProperties.$echarts = echarts

app.use(VMdPreview)

app.use(ElementPlus)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(router).mount('#app')
